package com.yilin.platform.base_core.components;

import com.yilin.platform.base_core.commons.utils.FtpUtil;
import org.apache.commons.net.ftp.FTPClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;

@Component
public class FptClient {
    private static Logger logger = LoggerFactory.getLogger(FptClient.class);


    private String host;
    private Integer port;
    private String username;
    private String password;


    /**
     * 文件下载
     */
    public void ftpDownload(String downloadPath, String savePath, String fileName) {
        try {
            logger.info("正在连接Ftp服务器,主机:" + host + ", 端口:" + port + ", 用户名:" + username + ", 密码:" + password);
            FTPClient clt = FtpUtil.getFtpClient(host, port, username, password);
            File file = new File(savePath);
            if (!file.exists()) file.mkdirs();
            FtpUtil.download(clt, downloadPath + "\\" + fileName, file.getPath() + "\\" + fileName);
        } catch (Exception e) {
            logger.error("连接FTP服务出现错误，异常：", e);
            e.printStackTrace();
        }
    }


}
